package org.moore.controller;

import org.moore.model.Map;
import org.moore.view.GameFrame;
import org.moore.view.GamePanel;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

// 选择关卡监听类
public class LevelButtonListener implements ActionListener {
    private final GamePanel gamePanel;

    public LevelButtonListener(GamePanel gamePanel) {
        this.gamePanel = gamePanel;
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        // 获取动作命令
        String action = e.getActionCommand();
        // 根据指令执行不同的代码
        switch (action) {
            // 低级
            case "lower" :
                new Map(9,9,1);
                GamePanel.getCardLayout().show(gamePanel,"game");
                // 同时设置菜单栏
                GameFrame.getGameBar().getLowerModeItem().setEnabled(false);
                GameFrame.getGameBar().getLowerModeItem().setText("初级[√]");
                break;
                // 中级
            case "midden" :
                new Map(9,9,2);
                GamePanel.getCardLayout().show(gamePanel,"game");
                // 同时设置菜单栏
                GameFrame.getGameBar().getMiddenModeItem().setEnabled(false);
                GameFrame.getGameBar().getMiddenModeItem().setText("中级[√]");
                break;
                // 高级
            case "premium" :
                new Map(9,9,3);
                GamePanel.getCardLayout().show(gamePanel,"game");
                // 同时设置菜单栏
                GameFrame.getGameBar().getPremiumModeItem().setEnabled(false);
                GameFrame.getGameBar().getPremiumModeItem().setText("高级[√]");
                break;
                // 返回
            case "back" :
                GamePanel.getCardLayout().show(gamePanel,"home");
                break;
        }
    }
}
